package com.cloud.pharmaceuticalClient.controller;

import com.cloud.pharmaceuticalClient.service.ProductPictureService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;


/**
 * @author zhozixiong
 * @date 2023/02/26
 */
@Slf4j
@CrossOrigin
@RestController
@RequiredArgsConstructor
public class TestController {

//    private final MinioUtil minioUtil;
    private final ProductPictureService productPictureService;

//    @PostMapping("/test")
//    public Object test(MultipartFile[] file, int did) throws Exception {
//        List<String> str = minioUtil.uploadFiles(file);
//        for (String string : str) {
//            productPictureService.insert(did, string);
//        }
//        return str;
//    }

//    @GetMapping("/test1")
//    public Object tests(HttpServletResponse response, @RequestParam("did") int did) throws Exception {
//        ProductPicture productPicture = productPictureService.searchByDid(did);
//        InputStream in = null;
//        OutputStream out = null;
//        try {
//            response.setContentType("image/png");
//            response.setCharacterEncoding("utf-8");
//            response.setHeader("Content-disposition", "attachment;filename=" + productPicture.getUrl());
//            out = response.getOutputStream();
//            in = minioUtil.getObject(productPicture.getUrl());
//            int len = 0;
//            byte[] bytes = new byte[1024];
//            while ((len = in.read(bytes)) > 0) {
//                out.write(bytes, 0, len);
//            }
//        } catch (IOException e) {
//            e.printStackTrace();
//            return "full";
//        } finally {
//            if (out != null) {
//                try {
//                    out.close();
//                } catch (IOException e) {
//                    log.error("out关闭出错");
//                }
//            }
//            if(in != null) {
//                try {
//                    in.close();
//                }catch (IOException e) {
//                    log.error("in关闭失败");
//                }
//            }
//        }
//        return "ok";
//    }
}
